package com.bjtu.lms.action.book;

import com.bjtu.lms.model.Book;
import com.bjtu.lms.service.BookService;
import com.opensymphony.xwork2.ActionSupport;

/**
 *
 * @author yilee
 */
public class ViewBookAction extends ActionSupport {

	private BookService bookService;
	private int id;
	private String result;

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public BookService getBookService() {
		return bookService;
	}

	public void setBookService(BookService bookService) {
		this.bookService = bookService;
	}

	@Override
	public String execute() throws Exception {
		Book book = bookService.findBooksById(id);
		if (book == null) {
			result = "{suc:0, msg:'图书不存在..'}";
		} else {
			result = "{suc:1, ISBN:'" + book.getISBN()
					+ "',name:'" + book.getName()
					+ "',synopsis:'" + book.getSynopsis()
					+ "',publish:'" + book.getPublish()
					+ "',publishTime:'" + book.getPublishTime()
					+ "',author:'" + book.getAuthor()
					+ "',price:'" + book.getPrice() + "'}";
		}
		return SUCCESS;
	}
}
